package com.huluobo.hyj.hyjmodel.ui.activity

import android.os.Handler
import com.huluobo.hyj.hyjmodel.R
import com.huluobo.hyj.hyjmodel.contract.splash.SplashContract
import com.huluobo.hyj.hyjmodel.contract.splash.SplashPresenter
import org.jetbrains.anko.startActivity

/**
 * logo页面实现判断是否登录跳转页面
 * */

class SplashActivity : BaseActivity(), SplashContract.View {

    private val presenter = SplashPresenter(this)

    override fun init() {
        super.init()
        presenter.checkLoginStatus() //是登陆还是主页面
    }

    companion object{
        const val DELAY = 2000L
    }
    //委托给lazy 实现懒加载
    private val handler by lazy {
        Handler()   //handler实例
    }

    // * 2.如果已经登录,则跳转到主页面
    override fun onLoggedIn() {
            startActivity<MainActivity>()
            finish()
    }

    // * 1.如果没有登录,延时2秒,跳转到登录界面
    override fun onNotLoggedIn() {
            handler.postDelayed(Runnable {
                startActivity<LoginActivity>()
                finish()
            }, DELAY)
    }

    //这个是加载布局
    override fun getLayoutResId(): Int = R.layout.activity_splash

}
